import 'package:finance_app/src/entities/leave_item_entity.dart';
import 'package:finance_app/src/entities/ocr_attachment_entity.dart';

leaveItemEntityFromJson(LeaveItemEntity data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['employee_id'] != null) {
		data.employeeId = json['employee_id'] is String
				? int.tryParse(json['employee_id'])
				: json['employee_id'].toInt();
	}
	if (json['employee_name'] != null) {
		data.employeeName = json['employee_name'].toString();
	}
	if (json['leave_type_id'] != null) {
		data.leaveTypeId = json['leave_type_id'] is String
				? int.tryParse(json['leave_type_id'])
				: json['leave_type_id'].toInt();
	}
	if (json['leave_type_name'] != null) {
		data.leaveTypeName = json['leave_type_name'].toString();
	}
	if (json['start_date'] != null) {
		data.startDate = json['start_date'].toString();
	}
	if (json['start_date_meridian'] != null) {
		data.startDateMeridian = json['start_date_meridian'].toString();
	}
	if (json['end_date'] != null) {
		data.endDate = json['end_date'].toString();
	}
	if (json['end_date_meridian'] != null) {
		data.endDateMeridian = json['end_date_meridian'].toString();
	}
	if (json['notes'] != null) {
		data.notes = json['notes'].toString();
	}
	if (json['days'] != null) {
		data.days = json['days'] is String
				? num.tryParse(json['days'])
				: json['days'];
	}
	if (json['action_at'] != null) {
		data.actionAt = json['action_at'];
	}
	if (json['action_by'] != null) {
		data.actionBy = json['action_by'];
	}
	if (json['rejected_reason'] != null) {
		data.rejectedReason = json['rejected_reason'];
	}
	if (json['attachments'] != null) {
		data.attachments = (json['attachments'] as List).map((v) => OcrAttachmentEntity().fromJson(v)).toList();
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	return data;
}

Map<String, dynamic> leaveItemEntityToJson(LeaveItemEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['employee_id'] = entity.employeeId;
	data['employee_name'] = entity.employeeName;
	data['leave_type_id'] = entity.leaveTypeId;
	data['leave_type_name'] = entity.leaveTypeName;
	data['start_date'] = entity.startDate;
	data['start_date_meridian'] = entity.startDateMeridian;
	data['end_date'] = entity.endDate;
	data['end_date_meridian'] = entity.endDateMeridian;
	data['notes'] = entity.notes;
	data['days'] = entity.days;
	data['action_at'] = entity.actionAt;
	data['action_by'] = entity.actionBy;
	data['rejected_reason'] = entity.rejectedReason;
	data['attachments'] =  entity.attachments?.map((v) => v.toJson())?.toList();
	data['status'] = entity.status;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	return data;
}